{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "40e77b78",
   "metadata": {},
   "source": [
    "* 2022-11-12/week11  \n",
    "* 课程：python  \n",
    "* 记录人：liuxu"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff0c62dc",
   "metadata": {},
   "source": [
    "# 本周内容  \n",
    "> 1. 元组\n",
    "> 2. 集合\n",
    "> 3. "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3d676d0b",
   "metadata": {},
   "source": [
    "## 元组  (tuple)\n",
    "> 1. 元组的概念和基本形态  \n",
    "> 2. 元组的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a1a0101d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1800001, 1800002, 1800003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "user_info = 1800001,1800002,1800003\n",
    "print(user_info,type(user_info))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7f8d3ae5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1800001, 1800002, 1800003] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "user_info_list = [1800001,1800002,1800003]\n",
    "print(user_info_list,type(user_info_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6113cbdd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1800001\n",
      "(1800001, 1800002)\n"
     ]
    }
   ],
   "source": [
    "# 取值\n",
    "print(user_info[0])\n",
    "# 切片\n",
    "print(user_info[:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ec549e19",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "e04c9b6f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=11, tm_mday=2, tm_hour=19, tm_min=11, tm_sec=29, tm_wday=2, tm_yday=306, tm_isdst=0)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ead2faf6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1667387542.8715758"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.time()# 时间戳，可以记录互联网中所有产生的 数据信息的产生、销毁、创建一系列行为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3f3a45e0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.count(1800001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8aa01903",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.index(1800002)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7db289ba",
   "metadata": {},
   "source": [
    "## 2.集合  \n",
    "\n",
    "> 1. 集合的概念和性质  \n",
    ">> 1. 集合的唯一性  \n",
    ">> 2. 集合的无序性  \n",
    "> 2. 集合的方法  \n",
    ">> 1. 交集：逻辑运算符： setA&setB  setA.intersection(B)\n",
    ">> 2. 并集：逻辑运算符： setA|setB  setA.union(B)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d943bbc3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'banana', 'apple', 'pear', 'orange'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}\n",
    "print(basket,type(basket))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "4bd7b805",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社_user_id = {1800002,1800003,1800111,1800122}\n",
    "合唱团_user_id = {1800003,1800009,1800007,1800111,1801111}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5bea8b7a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800003, 1800111}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id & 合唱团_user_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "fffa68ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800003, 1800111}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.intersection(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e17acc1f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id)+ len(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "02bf4832",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id | 合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "ead13d42",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800002, 1800003, 1800007, 1800009, 1800111, 1800122, 1801111}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.union(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "1679d303",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社_user_id_list = [1800002,1800003,1800111,1800122]\n",
    "合唱团_user_id_list = [1800003,1800009,1800007,1800111,1801111]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bcb155d8",
   "metadata": {},
   "source": [
    "## 3.字典(dict)  \n",
    "\n",
    "> 1. 字典的概念和性质  \n",
    "> 2. 字典的创建  \n",
    "> 3. 字典的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "d1a74c2d",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character '，' (U+FF0C) (2110139547.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [26]\u001b[1;36m\u001b[0m\n\u001b[1;33m    \"jiwadhy443hh\":[\"zhichao\",\"冰岛\",\"朋友圈\"，\"男\",\"159\",\"置顶聊天\",\"会话\"],\u001b[0m\n\u001b[1;37m                                        ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character '，' (U+FF0C)\n"
     ]
    }
   ],
   "source": [
    "wechat = {\n",
    "    \"jiwadhy443hh\":[\"zhichao\",\"冰岛\",\"朋友圈\"，\"男\",\"159\",\"置顶聊天\",\"会话\"],\n",
    "    \"hjhdhcuwe321\":[\"Jack\",\"香港\"]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "fc7002bf",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'wechat' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [27]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mwechat\u001b[49m[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mjiwadhy443hh\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n",
      "\u001b[1;31mNameError\u001b[0m: name 'wechat' is not defined"
     ]
    }
   ],
   "source": [
    "wechat[\"jiwadhy443hh\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "a6f0a8fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新1班 = {\n",
    "    1800001:\"李华\",\n",
    "    1800002:\"小明\",\n",
    "    1800003:\"Jack\",\n",
    "    1800004:\"Marry\"\n",
    "    \n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "6ce10d8f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1800001: '李华', 1800002: '小明', 1800003: 'Jack', 1800004: 'Marry'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新1班,type(网新1班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b68985f4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
